#include "fig_boss_attackmove_manager.h"
#include "fig_enemy_boss.h"
#include "fig_boss_attackmove.h"
#include "fig_boss_attackmove_godown.h"
#include "fig_boss_attackmove_rightleft.h"
#include "fig_boss_attackmove_circle.h"


FIGBossAttackMoveManager::FIGBossAttackMoveManager() :
														m_pBoss(NULL),
														m_pCurrentAttackMove(NULL)
{
	for(int i = 0; i < (int)ATTACK_MOVEMENT_C; i++)
	{
		m_pAttackMoves[i] = NULL;
	}
}

FIGBossAttackMoveManager&	FIGBossAttackMoveManager::Instance()
{
	static FIGBossAttackMoveManager	Inst;
	return Inst;
}



void		FIGBossAttackMoveManager::Clear()
{
	for(int i = 0; i < (int)ATTACK_MOVEMENT_C; i++)
	{
		UTIL_SAFE_DELETE(m_pAttackMoves[i]);
	}
	m_pCurrentAttackMove = NULL;
}


void		FIGBossAttackMoveManager::Tick(float dt)
{
	if(m_pCurrentAttackMove)
	{
		m_pCurrentAttackMove->Tick(dt);
	}
}

void		FIGBossAttackMoveManager::HandleMe(FIGEnemyBoss* pBoss)
{
	m_pBoss = pBoss;			
}


bool		FIGBossAttackMoveManager::ShouldDisableOtherMovement()
{
	if(m_pCurrentAttackMove)
	{
		if(m_pCurrentAttackMove->m_Delay > 0)
			return false;

		return m_pCurrentAttackMove->ShouldDisableOtherMovement();
	}

	return false;
}
	
bool		FIGBossAttackMoveManager::ShouldDisableAttack()
{
	if(m_pCurrentAttackMove)
	{
		if(m_pCurrentAttackMove->m_Delay > 0)
			return false;

		return m_pCurrentAttackMove->ShouldDisableAttack();
	}

	return false;
}

bool		FIGBossAttackMoveManager::ShouldDisableBoneMovement()
{
	if(m_pCurrentAttackMove)
	{
		if(m_pCurrentAttackMove->m_Delay > 0)
			return false;

		return m_pCurrentAttackMove->ShouldDisableBoneMovement();
	}

	return false;
}


void		FIGBossAttackMoveManager::Start(ATTACK_MOVEMENT Type,float Delay)
{
	// preivous one is still active
	if(m_pCurrentAttackMove)
		return;

	FIGBossAttackMove* pMove = m_pAttackMoves[Type];
	if(!pMove)
	{	
		switch(Type)
		{	
			case ATTACK_MOVEMENT_GODOWN_SPEEDLY:
				pMove = new FIGBossAttackMoveGoDown(this);
			break;

			case ATTACK_MOVEMENT_RIGHT_AND_LEFT:
				pMove = new FIGBossAttackMoveRightLeft(this);
			break;

			case ATTACK_MOVEMENT_CIRCLE:
				pMove = new FIGBossAttackMoveCircle(this);
			break;
			default:
			break;
		}
		
	}
	m_pAttackMoves[Type] = pMove;

	m_pCurrentAttackMove = pMove;
	if(m_pCurrentAttackMove)
		m_pCurrentAttackMove->Start(Delay);
}

void		FIGBossAttackMoveManager::End()
{
	 m_pCurrentAttackMove = NULL;
}

bool		FIGBossAttackMoveManager::IsActive() const
{
	if(m_pCurrentAttackMove)
		return true;

	return false;
}